ArcPadScripting
Geometric Objects Example

Description

GeometricExample gets the ShapeType and geometric shape for the selected feature, displays the ShapeType in a message box, and calls Parts or PntInfo to display information about the feature's parts or vertices, respectively.

Parts takes a geometric shape and ShapeType as arguments. For each part of the geometric shape, it displays the number of vertices in a message box and calls PntInfo to display information about each vertex.

PntInfo takes a point or vertex, shape type, and vertex index as arguments. It displays coordinate information for the point or vertex in a message box.

VBScript Code

Copy Code
Sub GeometricExample
 Dim objSelLayer, objRS, objSH, lngSHType 
    ' Get the layer of the selected feature
 Set objSelLayer = Application.Map.SelectionLayer   
 'If no feature has been selected, exit the subroutine
   If objSelLayer Is Nothing Then
    MsgBox "No feature has been selected",vbExclamation,"Selection Null"
     Exit Sub 
 End If
   'Get the selected feature's geometric shape. 
 Set objRS = objSelLayer.Records
    objRS.Bookmark = Application.Map.SelectionBookmark   
 Set objSH = objRS.Fields.Shape
    'Get the selected feature's ShapeType.
 lngSHType = objSH.ShapeType     
    'Get the geometry of the feature.   Must be handled differently depending on the ShapeType.
 Select Case lngSHType     
    'Point Feature
  Case 1
   MsgBox "This is a point feature",vbOKOnly,"Point feature"
   'Call routine to get the point's x,y coordinates
   Call PntInfo(objSH, lngSHType, "Point")
  'PolyLine Feature     
  Case 3
   MsgBox "This is a polyline feature that contains " & objSH.Parts.Count & " part(s).",vbOKOnly,"Polyline Feature"
   'Call routine to get the line's parts
   Call Parts(objSH, lngSHType)
  'Polygon Feature                      
  Case 5
   MsgBox "This is a Polygon feature that contains " & objSH.Parts.Count & " part(s).",vbOKOnly,"Polygon Feature"
   'Call routine to get the polygon's parts
   Call Parts(objSH, lngSHType)
  'PointZ Feature     
  Case 11
   MsgBox "This is a PointZ Feature",vbOKOnly,"PointZ Feature"
   'Call routine to get the point's x,y,z coordinates
   Call PntInfo(objSH, lngSHType, "Point") 
  'PolyLineZ Feature     
  Case 13
   MsgBox "This is a PolylineZ feature that contains " & objSH.Parts.Count & " part(s).",vbOKOnly,"PolylineZ Feature"
   'Call routine to get the polyline's parts
   Call Parts(objSH, lngSHType)
  'PolygonZ Feature     
  Case 15
   MsgBox "This is a PolygonZ feature that contains " & objSH.Parts.Count & " part(s).",vbOKOnly,"PolygonZ Feature"
   'Call routine to get the polygon's parts
   Call Parts(objSH, lngSHType)
  'PointM Feature     
  Case 21
   MsgBox "This is a PointM Feature",vbOKOnly,"PointM Feature"
   'Call routine to get the point's x,y,z coordinates and m value
   Call PntInfo(objSH, lngSHType, "Point")
   'PolylineM Feature     
  Case 23
   MsgBox "This is a PolylineM feature that contains " & objSH.Parts.Count & " part(s).",vbOKOnly,"PolylineM Feature"
   'Call routine to get the polyline's parts
   Call Parts(objSH, lngSHType)
  'PolygonM Feature     
  Case 25
   MsgBox "This is a PolygonM feature that contains " & objSH.Parts.Count & " part(s).",vbOKOnly,"PolygonM Feature"
   'Call routine to get the polygon's parts
   Call Parts(objSH, lngSHType) 
  'Unknown Feature     
  Case Else
   MsgBox "Unknown Feature Type",vbExclamation,"Feature Type Unknown"   
 End Select 
   Set objSH = Nothing
 Set objRS = Nothing
   Set objSelLayer = Nothing
End Sub

Sub Parts(objSH, lngSHType)
 Dim intJ, intI, objPart, objVertex
   'Initialize intJ
 intJ = 1
   'Display information for each part of the feature
 For Each objPart in objSH.Parts
     MsgBox "Part " & intJ & " contains " & objPart.Count & " vertices.",vbOKOnly," Vertex Count"
   'Initialize intI     
   intI = 1
    'Display information for each vertex in the current part
   For Each objVertex in objPart
       strVertexNo = "vertex(" & intI & ")"
       Call PntInfo(objVertex, lngSHType, strVertexNo)
       'Increment intI
     intI = intI + 1
    Next
   'Increment intJ
     intJ = intJ + 1
 Next
End Sub

Sub PntInfo(objSH, lngSHType, strVertexNo)
   Dim strMeasureInfo, strZinfo
   'If the vertex or point contains a valid Measure value, get it.
   If objSH.IsMeasured = True Then
    strMeasureInfo = "and contains an M value of: " & objSH.Measure & "."
   End If
   'If the selected feature is a PointZ, PolylineZ, or PolygonZ, get the Z value.       
   If lngSHType = 11 or lngSHType = 13 or lngSHType = 15 Then
     strZinfo = ", " & objSH.Z
   End If     
   'Display the coordinate information of the vertex or point   
   MsgBox "The coordinate information for the current point or vertex is: " &_
       VBCr & objSH.X & ", " & objSH.Y & strZinfo &_
       VBCr & strMeasureInfo,vbOKOnly,strVertexNo & " Coordinate Information."
End Sub